Declare @StartDate as datetime
Declare @EndDate as datetime

SET @StartDate = '01-Sep-2014'
SET @EndDate = '30-Sep-2014'

--SELECT COUNT(CH.ContactHistoryID)
--FROM tblContactHistory CH 
--	INNER JOIN tblTaskHistory TH ON CH.BNInfo1 = TH.TaskHistoryID
--	INNER JOIN tblTask T ON TH.TAskID = T.TaskID
--	INNER JOIN tblUser U ON CH.LogBy = U.UserID
--	INNER JOIN tblTeam TM ON U.TeamID = TM.TeamID
--	Where (Convert(varchar(8), T.ClosedDate, 112) Between Convert(varchar(8), @StartDate, 112) And Convert(varchar(8), @EndDate, 112))
--	And CH.SourceID IN (4,6)
--	And T.[Status] = 100
--	And TM.TeamTypeID = 1
--	And CH.BNInfo1 > 0

--SELECT COUNT(CH.ContactHistoryID)
--FROM tblContactHistory CH 
--		INNER JOIN tblTaskHistory TH ON CH.BNInfo1 = TH.TaskHistoryID
--		INNER JOIN tblTask T ON TH.TAskID = T.TaskID
--		INNER JOIN tblUser U ON CH.LogBy = U.UserID
--		INNER JOIN tblTeam TM ON U.TeamID = TM.TeamID
--		Where (Convert(varchar(8), T.ClosedDate, 112) Between Convert(varchar(8), @StartDate, 112) And Convert(varchar(8), @EndDate, 112))
--		And CH.SourceID IN (4,6) 
--		And T.[Status] = 100
--		And TM.TeamTypeID = 1
--		And CH.BNInfo1 > 0
--		And T.SNInfo6 <= 1


--select count(*) from tblTask T
--Where (Convert(varchar(8), T.ClosedDate, 112) Between Convert(varchar(8), @StartDate, 112) And Convert(varchar(8), @EndDate, 112))
--And T.CaseSourceID IN (4,6) 
--And T.[Status] = 100
--And T.SNInfo6 <= 1


--select * from tblEmail Where EmailSubject LIKE '%<%>%'

Select CaseRefNo FROM tblContactHistory
		Where  (Convert(varchar(8), LogStart, 112) Between Convert(varchar(8), @StartDate, 112) And Convert(varchar(8), @EndDate, 112))
		And EnquiryTypeID = 473 And SourceID IN (4,6)
--		And CaseRefNo = 'C147-341981'

--select * from tblContactHistory Where CaseRefNo = 'C147-341981'

--select * from tblContactHistory Where Info1 IS NOT NULL

--Update tblContactHistory SET EnquiryTypeID = 473, Info1 = 'ORG EnquiryTypeID = 464' Where CaseRefNo = 'C147-341981'